package com.cg.design.graphicdesignpattern.singleton;

/**
 * 最多能生成3个实例的类
 *
 * @program: LeetCode->Triple
 * @description: 最多能生成3个实例的类
 * @author: cg
 * @create: 2022-03-19 16:18
 **/
public class Triple {

    private static Triple[] triples = new Triple[]{
            new Triple(0),
            new Triple(1),
            new Triple(2),
    };

    private int id;

    private Triple(int id) {
        System.out.println("The instance " + id + " is created.");
        this.id = id;
    }

    public static Triple getInstance(int id) {
        return triples[id];
    }

    @Override
    public String toString() {
        return "[Triple" +
                "id=" + id +
                ']';
    }
}
